package com.cx.service.impl;

import com.cx.dao.CommentMapper;
import com.cx.dao.UserMapper;
import com.cx.pojo.Comment;
import com.cx.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void addComment(Integer id, String content) {
        commentMapper.addComment(id, content);
    }

    @Override
    public void addCommentReply(Integer id, String content, Integer pid) {
        commentMapper.addCommentReply(id, content, pid);
    }

    @Override
    public void deleteCommentById(Integer id) {
        commentMapper.deleteCommentById(id);
    }

    //根据用户ID查询全部评论
    @Override
    public List<Comment> getCommentAllById(Integer id) {
        return commentMapper.getCommentAllById(id);
    }

    //    查询全部评论(二级评论模式)
    @Override
    public List<Comment> getCommentAll() {
//        父评论
        List<Comment> parentComments = commentMapper.getCommentAll();
        //遍历父评论
        for (Comment list : parentComments) {
        //根据当前ID查询评论用户信息
            list.setUser(userMapper.getUserById(list.getUserId()));
            //根据当夫ID查询子评论
            List<Comment> SubComments = commentMapper.getCommentById(list.getId());
            for (Comment subComment : SubComments) {
                //根据当前ID查询评论用户信息
                subComment.setUser(userMapper.getUserById(list.getUserId()));
            }
//            将子评论加入父评论
            list.setComments(SubComments);
        }
//        返回父子评论
        return parentComments;
    }
//
//    @Override
//    public void getAllClubResourceById(Integer id, String contentName, String content) {
//        commentMapper.getAllClubResourceById(id, contentName, content);
//    }
//
//    @Override
//    public void getDeleteClubResourceById(Integer id) {
//        commentMapper.getDeleteClubResourceById(id);
//    }
//
//    @Override
//    public List<String> getClubByIdList(Integer id) {
//        return commentMapper.getClubByIdList(id);
//    }
//
//    @Override
//    public String getClubById(Integer id) {
//        return commentMapper.getClubById(id);
//    }
}
